<?php /*
@session_start();
 if((!isset($_SESSION["kt_login_id"]) && !isset($_SESSION["kt_login_user"]) &&  !isset($_SESSION["kt_login_level"])) ) {

    header("Location: login.php");
    exit;
	
}else{

$level = addslashes($_SESSION['kt_login_user']);
$user = addslashes($_SESSION['kt_login_level']);

echo $level;
echo $user;
}*/

require_once("classes/respondent.class.php");
require_once("classes/language.class.php");
require_once("classes/country.class.php");
require_once("classes/nationality.class.php");
require_once("classes/newsletter.class.php");
require_once("classes/util/utilitarios.class.php");

//Instanciando Objetos
$respondent 	= new Respondent();
$language 		= new Language();
$country 		= new Country();
$nationality 	= new Nationality();
$newsletter 	= new Newsletter();
$utilitario 	= new Util();

//Invocando metodo

$listLanguage		= $language->listObject();
$listCountry 		= $country->listObject(); 
$listNationality	= $nationality->listObject(); 
$listNewsletter		= $newsletter->listNewsletterObject(); 


//Pegando valores do post Filtro
if(isset($_POST['action'])&& $_POST['action']=='filter'){

	$fk_country		= $_POST['country'];
	$fk_language	= $_POST['language'];
	$fk_nationality	= $_POST['nationality'];
	$sex			= $_POST['sex'];
	$name			= $_POST['name'];
	$familyname		= $_POST['surname'];
	$birthday		= $_POST['birthday'];
	$registroem		= $_POST['registered'];

$dadosFiltro = array('fk_country'=>$fk_country, 'fk_language'=>$fk_language, 'fk_nationality'=>$fk_nationality, 'sex'=>$sex,
  'name'=>$name, 'familyname'=>$familyname, 'birthday'=>$birthday, 'registroem'=>$registroem);
  $listRespondent 	= $respondent->filterObject($dadosFiltro);
}else{
	$listRespondent = $respondent->listObject();

}

// Gerando vetor para formatação
while($row = mysql_fetch_assoc($listRespondent)){
  $arr[] = $row; 
}
$i = 1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/user2.dwt.php" codeOutsideHTMLIsLocked="false" --><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>QS Controller</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEditableHeadTag -->
<!-- InstanceEndEditable -->
<style type="text/css" media="all">
<!--
@import url("css/basics.css");
-->
</style>
<!-- TinyMCE -->
<script type="text/javascript" src="includes/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript"
   src="includes/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
    	mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
theme_advanced_buttons1:
"code,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,cleanup,link,unlink,image,table",

		// Theme options
		theme_advanced_buttons2 : "formatselect,fontselect,fontsizeselect,forecolor,backcolor,fullscreen",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",


		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
	 content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
    file_browser_callback : "tinyBrowser",
		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
<!-- /TinyMCE -->

</head>
<body>
<div id="box">
<div id="topo">
<span>
<img src="images/logo.png" alt="QS Controller" width="293" height="112"  />
</span>
<p>Version: 1.0</p>
<p>Status: Beta </p>
<p><!-- InstanceBeginEditable name="logout" -->logout<!-- InstanceEndEditable --></p>

</div><!-- end div topo-->
<div id="menuhorizontal">
  <table width="500" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td><a href="index.php">Home</a></td>
       <td><a href="registered.php">People</a></td>
        <td><a href="newsletterList.php">Newsletter</a></td>
        
      <td><a href="statistics.php">Statistics</a></td>
    </tr>
  </table>


</div><!-- end div menuhorizontal -->

<div id="content">
<!-- InstanceBeginEditable name="content" -->  
<div id="menudiv" >
<?php
$utilitario->menu('newsletter');
?>
</div><!-- end div submenu -->
   <div class="KT_tng" >
      <h1> DIRECT MAIL</h1>
      <div class="msgerror" id="msgerror">
      <?php ?>
      </div>
	<div style="background:#CDCDCD; display:block;">
	<h2>Filter</h2>
     	<form name="filterForm" action="" method="POST" enctype="multipart/form-data">
		<table  border="0" cellspacing="2">
  <tr>
    <td >Country</td>
    <td><select name="country" id="country" style="width:200px;">
	<option value="">Select</option>
		<?php	
			while($listCou =mysql_fetch_assoc($listCountry) ){
			echo '<option value="'.$listCou['idcountry'].'">'.$listCou['countryname'].'</option>';
			}
		?>
		</select></td>
    <td >Language</td>
    <td ><select name="language" id="language" style="width:200px;">
	<option value="">Select</option>
		<?php	
			while($listLan =mysql_fetch_assoc($listLanguage) ){
			echo '<option value="'.$listLan['idlanguage'].'">'.$listLan['languagename'].'</option>';
			}
		?>
    </select></td>
    <td >Nationality</td>
    <td><select name="nationality" id="nationality" style="width:200px;">
	<option value="">Select</option>
		<?php	
			while($listNat =mysql_fetch_assoc($listNationality) ){
			echo '<option value="'.$listNat['idnationality'].'">'.$listNat['nationalityname'].'</option>';
			}
		?>
    </select></td>
  </tr>
  <tr>
    <td >Sex</td>
    <td><select name="sex" id="sex" style="width:200px;">
	<option value="">Select</option>
	<option value="F">Female</option>
	<option value="M">Male</option>
    </select></td>
    <td>Name</td>
    <td><input type="text" name="name" id="name" style="width:195px;" /></td>
    <td>Surname</td>
    <td><input type="text" name="surname" id="surname" style="width:195px;" /></td>
  </tr>
  <tr>
    <td>Birthday</td>
    <td><input type="text" name="birthday" id="birthday" style="width:195px;" /></td>
    <td>Registered</td>
    <td><input type="text" name="registered" id="registered" style="width:195px;" /></td>
    <td>&nbsp;</td>
    <td>
	<input type="hidden" name="action" id="action" value="filter" style="width:195px;" />
	<input type="submit" name="submit" id="submit" value="Filter" style="width:195px;" /></td>
  </tr>
</table>
		
	
		</form>
		
	  </div>
<form  name="send"  action="directMailSend.php" method="POST" enctype="multipart/form-data">
		<div style="background:#CDCDCD; display:block;">
		

		<h2>Newsletter</h2>

		<table><tr>		<td >Select the Newsletter</td>
    <td ><select name="newsletter" id="newsletter"
	onChange="javascript:if(options[selectedIndex].value) window.open('newsletterpage.php?newsletter='+options[selectedIndex].value,'','scrollbars=yes,width=650,height=450')">
	<option value="">Select</option>
		<?php	
			while($listNews =mysql_fetch_assoc($listNewsletter) ){
			echo '<option value="'.$listNews['ID'].'">'."Ano: ".$listNews['ANO']." - No.: ".$listNews['NUMERO']." - Mês: ".$listNews['MES']." - Idioma: ".$listNews['IDIOMA'].'</option>\n';
			}
			
		?>
		
		
    </select></td><td></td></tr>

	</table>
		</div>
		
		

  <?php 
  //Gerando saida dos resultados
	echo $utilitario->array2table($arr, false,'&nbsp;',FALSE,NULL);
   ?>
   <input type="submit" name="submit" value="Send Data"/>
   </form>
    </div><!-- InstanceEndEditable -->
</div><!-- end div content -->
</div> <!-- end div box -->

</body>
<!-- InstanceEnd --></html>
